<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>单元测试与配置文件 | 浪飞IT小栈</title>
    <meta name="generator" content="VuePress 1.9.9">
    <link rel="icon" href="/img/favicon.ico">
    <meta name="description" content="前后端技术分享">
    <meta name="keywords" content="前端博客,后端博客,人工智能,个人技术博客,前端,前端开发,前端框架,web前端,前端面试题,技术文档,学习,面试,JavaScript,js,ES6,TypeScript,vue,python,css3,html5,Node,git,github,markdown,java,Spring,Springboot,Redis,mysql">
    <meta name="baidu-site-verification" content="7F55weZDDc">
    <meta name="theme-color" content="#11a8cd">
    
    <link rel="preload" href="/assets/css/0.styles.ada71c49.css" as="style"><link rel="preload" href="/assets/js/app.a2a00aa5.js" as="script"><link rel="preload" href="/assets/js/2.256f807a.js" as="script"><link rel="preload" href="/assets/js/28.b383a871.js" as="script"><link rel="prefetch" href="/assets/js/10.ab144fe3.js"><link rel="prefetch" href="/assets/js/11.062e0879.js"><link rel="prefetch" href="/assets/js/12.f9c60882.js"><link rel="prefetch" href="/assets/js/13.0a6ebfcf.js"><link rel="prefetch" href="/assets/js/14.03fc6f12.js"><link rel="prefetch" href="/assets/js/15.19dbf9fd.js"><link rel="prefetch" href="/assets/js/16.6e68160b.js"><link rel="prefetch" href="/assets/js/17.1d678834.js"><link rel="prefetch" href="/assets/js/18.4536fd5c.js"><link rel="prefetch" href="/assets/js/19.9c1b65df.js"><link rel="prefetch" href="/assets/js/20.c5f96e71.js"><link rel="prefetch" href="/assets/js/21.3f0b334e.js"><link rel="prefetch" href="/assets/js/22.55c868be.js"><link rel="prefetch" href="/assets/js/23.91286241.js"><link rel="prefetch" href="/assets/js/24.c1af1909.js"><link rel="prefetch" href="/assets/js/25.a995a755.js"><link rel="prefetch" href="/assets/js/26.abc5dea3.js"><link rel="prefetch" href="/assets/js/27.1eb62850.js"><link rel="prefetch" href="/assets/js/29.088e0d73.js"><link rel="prefetch" href="/assets/js/3.cd716564.js"><link rel="prefetch" href="/assets/js/30.3ccc98d5.js"><link rel="prefetch" href="/assets/js/31.aab7cc23.js"><link rel="prefetch" href="/assets/js/32.5e16b7e6.js"><link rel="prefetch" href="/assets/js/33.4aaeb741.js"><link rel="prefetch" href="/assets/js/34.45e8e898.js"><link rel="prefetch" href="/assets/js/35.5899c97a.js"><link rel="prefetch" href="/assets/js/36.32e2e263.js"><link rel="prefetch" href="/assets/js/37.c4e27bbd.js"><link rel="prefetch" href="/assets/js/38.fe5e60d2.js"><link rel="prefetch" href="/assets/js/39.2cb0b4ee.js"><link rel="prefetch" href="/assets/js/4.edf4d5e7.js"><link rel="prefetch" href="/assets/js/40.08d5bead.js"><link rel="prefetch" href="/assets/js/41.2f80f24b.js"><link rel="prefetch" href="/assets/js/42.43a49913.js"><link rel="prefetch" href="/assets/js/43.08da7ec2.js"><link rel="prefetch" href="/assets/js/44.7c7cb8a9.js"><link rel="prefetch" href="/assets/js/45.0ddf7e7f.js"><link rel="prefetch" href="/assets/js/46.7c4609a5.js"><link rel="prefetch" href="/assets/js/47.edf3ddf8.js"><link rel="prefetch" href="/assets/js/48.569a90b9.js"><link rel="prefetch" href="/assets/js/49.fa368ac8.js"><link rel="prefetch" href="/assets/js/5.24054156.js"><link rel="prefetch" href="/assets/js/50.b9b3ea7f.js"><link rel="prefetch" href="/assets/js/51.a2ebf0fe.js"><link rel="prefetch" href="/assets/js/52.31f02238.js"><link rel="prefetch" href="/assets/js/53.4110ef1e.js"><link rel="prefetch" href="/assets/js/54.dab741c7.js"><link rel="prefetch" href="/assets/js/55.f27984e9.js"><link rel="prefetch" href="/assets/js/56.bd4c1a8e.js"><link rel="prefetch" href="/assets/js/57.375d40cb.js"><link rel="prefetch" href="/assets/js/58.932e3864.js"><link rel="prefetch" href="/assets/js/59.e657be1b.js"><link rel="prefetch" href="/assets/js/6.b259c061.js"><link rel="prefetch" href="/assets/js/60.88d94274.js"><link rel="prefetch" href="/assets/js/61.fa71d884.js"><link rel="prefetch" href="/assets/js/62.a9d3b3b7.js"><link rel="prefetch" href="/assets/js/63.f849fe75.js"><link rel="prefetch" href="/assets/js/64.1770f7a9.js"><link rel="prefetch" href="/assets/js/65.6afc33db.js"><link rel="prefetch" href="/assets/js/66.799f2eb4.js"><link rel="prefetch" href="/assets/js/67.f36b2f7d.js"><link rel="prefetch" href="/assets/js/68.868cd00b.js"><link rel="prefetch" href="/assets/js/69.4c29b907.js"><link rel="prefetch" href="/assets/js/7.e34ea00f.js"><link rel="prefetch" href="/assets/js/70.1b993ed4.js"><link rel="prefetch" href="/assets/js/71.e16ad4f9.js"><link rel="prefetch" href="/assets/js/72.627505e6.js"><link rel="prefetch" href="/assets/js/73.32768e14.js"><link rel="prefetch" href="/assets/js/74.968a580d.js"><link rel="prefetch" href="/assets/js/75.42d5af3d.js"><link rel="prefetch" href="/assets/js/76.19a69d31.js"><link rel="prefetch" href="/assets/js/77.cf627a78.js"><link rel="prefetch" href="/assets/js/78.07177880.js"><link rel="prefetch" href="/assets/js/8.c4dd00ce.js"><link rel="prefetch" href="/assets/js/9.0ff73be2.js">
    <link rel="stylesheet" href="/assets/css/0.styles.ada71c49.css">
  </head>
  <body class="theme-mode-light">
    <div id="app" data-server-rendered="true"><div class="theme-container sidebar-open have-rightmenu"><header class="navbar blur"><div title="目录" class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><img src="/img/logo.png" alt="浪飞IT小栈" class="logo"> <span class="site-name can-hide">浪飞IT小栈</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/" class="nav-link">首页</a></div><div class="nav-item"><a href="/pages/6138ae/" class="nav-link">Java速通</a></div><div class="nav-item"><a href="/pages/705b35/" class="nav-link">面试经典</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="精品项目" class="dropdown-title"><a href="/project/" class="link-title">精品项目</a> <span class="title" style="display:none;">精品项目</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>桌面端</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/pages/8143cc480faf9a11/" class="nav-link">JavaScript</a></li></ul></li><li class="dropdown-item"><h4>PC后端</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/note/javascript/" class="nav-link">项目1</a></li><li class="dropdown-subitem"><a href="/note/typescript-axios/" class="nav-link">项目二</a></li></ul></li></ul></div></div><div class="nav-item"><a href="/about/" class="nav-link">电子书</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="索引" class="dropdown-title"><a href="/archives/" class="link-title">索引</a> <span class="title" style="display:none;">索引</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/categories/" class="nav-link">分类</a></li><li class="dropdown-item"><!----> <a href="/tags/" class="nav-link">标签</a></li><li class="dropdown-item"><!----> <a href="/archives/" class="nav-link">归档</a></li></ul></div></div><div class="nav-item"><a href="/pages/0c07b2/" class="nav-link">IT杂货铺</a></div><div class="nav-item"><a href="/archives/" class="nav-link">更多资源</a></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <div class="sidebar-hover-trigger"></div> <aside class="sidebar" style="display:none;"><div class="blogger"><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/avatar.jpg"> <div class="blogger-info"><h3>浪飞yes</h3> <span>无法简单的人儿~</span></div></div> <nav class="nav-links"><div class="nav-item"><a href="/" class="nav-link">首页</a></div><div class="nav-item"><a href="/pages/6138ae/" class="nav-link">Java速通</a></div><div class="nav-item"><a href="/pages/705b35/" class="nav-link">面试经典</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="精品项目" class="dropdown-title"><a href="/project/" class="link-title">精品项目</a> <span class="title" style="display:none;">精品项目</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>桌面端</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/pages/8143cc480faf9a11/" class="nav-link">JavaScript</a></li></ul></li><li class="dropdown-item"><h4>PC后端</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/note/javascript/" class="nav-link">项目1</a></li><li class="dropdown-subitem"><a href="/note/typescript-axios/" class="nav-link">项目二</a></li></ul></li></ul></div></div><div class="nav-item"><a href="/about/" class="nav-link">电子书</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="索引" class="dropdown-title"><a href="/archives/" class="link-title">索引</a> <span class="title" style="display:none;">索引</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/categories/" class="nav-link">分类</a></li><li class="dropdown-item"><!----> <a href="/tags/" class="nav-link">标签</a></li><li class="dropdown-item"><!----> <a href="/archives/" class="nav-link">归档</a></li></ul></div></div><div class="nav-item"><a href="/pages/0c07b2/" class="nav-link">IT杂货铺</a></div><div class="nav-item"><a href="/archives/" class="nav-link">更多资源</a></div> <!----></nav>  <ul class="sidebar-links"><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>开篇</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>基础语法</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>面向对象</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>常用类</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading open"><span>基础高级</span> <span class="arrow down"></span></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/pages/0c7696/" class="sidebar-link">集合框架</a></li><li><a href="/pages/19e70b/" class="sidebar-link">异常机制</a></li><li><a href="/pages/a53030/" class="sidebar-link">多线程</a></li><li><a href="/pages/16b819/" class="sidebar-link">IO</a></li><li><a href="/pages/258730/" aria-current="page" class="active sidebar-link">单元测试与配置文件</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level2"><a href="/pages/258730/#一、今日内容与目标" class="sidebar-link">一、今日内容与目标</a></li><li class="sidebar-sub-header level2"><a href="/pages/258730/#二、企业开发注意" class="sidebar-link">二、企业开发注意</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/pages/258730/#_2-1-开发环境" class="sidebar-link">2.1 开发环境</a></li><li class="sidebar-sub-header level3"><a href="/pages/258730/#_2-2-idea-配置注意" class="sidebar-link">2.2 idea 配置注意</a></li><li class="sidebar-sub-header level4"><a href="/pages/258730/#_2-2-1-项目编码设置-掌握" class="sidebar-link">2.2.1 项目编码设置(掌握)</a></li><li class="sidebar-sub-header level4"><a href="/pages/258730/#_2-2-2-新项目编码设置" class="sidebar-link">2.2.2 新项目编码设置</a></li><li class="sidebar-sub-header level4"><a href="/pages/258730/#_2-2-3-调整字体大小" class="sidebar-link">2.2.3 调整字体大小</a></li><li class="sidebar-sub-header level4"><a href="/pages/258730/#_2-2-4-设置为-eclipse-快捷键-了解" class="sidebar-link">2.2.4 设置为 eclipse 快捷键(了解)</a></li><li class="sidebar-sub-header level3"><a href="/pages/258730/#_2-3-软件开发概述-了解" class="sidebar-link">2.3 软件开发概述（了解）</a></li><li class="sidebar-sub-header level4"><a href="/pages/258730/#_2-3-1-软件的生命周期" class="sidebar-link">2.3.1 软件的生命周期</a></li><li class="sidebar-sub-header level4"><a href="/pages/258730/#_2-3-2-软件设计原则" class="sidebar-link">2.3.2 软件设计原则</a></li><li class="sidebar-sub-header level3"><a href="/pages/258730/#_2-4-编码规范" class="sidebar-link">2.4 编码规范</a></li><li class="sidebar-sub-header level4"><a href="/pages/258730/#_2-4-1-为什么要有规范" class="sidebar-link">2.4.1 为什么要有规范？</a></li><li class="sidebar-sub-header level4"><a href="/pages/258730/#_2-4-2-alibaba-开发手册" class="sidebar-link">2.4.2 Alibaba 开发手册</a></li><li class="sidebar-sub-header level4"><a href="/pages/258730/#_2-4-3-sun-规范要求" class="sidebar-link">2.4.3 SUN 规范要求</a></li><li class="sidebar-sub-header level4"><a href="/pages/258730/#_2-4-5-呕心沥血整理的规范" class="sidebar-link">2.4.5 呕心沥血整理的规范</a></li><li class="sidebar-sub-header level4"><a href="/pages/258730/#_2-4-6-高薪秘诀" class="sidebar-link">2.4.6 高薪秘诀</a></li></ul></li><li class="sidebar-sub-header level2"><a href="/pages/258730/#三、jar-包使用" class="sidebar-link">三、Jar 包使用</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/pages/258730/#_3-1-jar-导出" class="sidebar-link">3.1 jar 导出</a></li><li class="sidebar-sub-header level3"><a href="/pages/258730/#_3-2-jar-导入" class="sidebar-link">3.2  jar 导入</a></li></ul></li><li class="sidebar-sub-header level2"><a href="/pages/258730/#四、软件测试" class="sidebar-link">四、软件测试</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/pages/258730/#_4-1-软件测试概述-了解" class="sidebar-link">4.1 软件测试概述(了解)</a></li><li class="sidebar-sub-header level3"><a href="/pages/258730/#_4-2-测试分类-了解" class="sidebar-link">4.2 测试分类(了解)</a></li><li class="sidebar-sub-header level4"><a href="/pages/258730/#_4-2-1-黑盒测试" class="sidebar-link">4.2.1 黑盒测试</a></li><li class="sidebar-sub-header level4"><a href="/pages/258730/#_4-2-2-白盒测试" class="sidebar-link">4.2.2 白盒测试</a></li><li class="sidebar-sub-header level3"><a href="/pages/258730/#_4-3-单元测试-junit-掌握" class="sidebar-link">4.3 单元测试 JUnit（掌握）</a></li><li class="sidebar-sub-header level4"><a href="/pages/258730/#_4-3-1-为什么需要-junit" class="sidebar-link">4.3.1 为什么需要 JUnit</a></li><li class="sidebar-sub-header level4"><a href="/pages/258730/#_4-3-2-junit4-使用步骤" class="sidebar-link">4.3.2 JUnit4 使用步骤</a></li><li class="sidebar-sub-header level5"><a href="/pages/258730/#_4-3-2-1-junit-4-依赖安装" class="sidebar-link">4.3.2.1 JUnit 4 依赖安装</a></li><li class="sidebar-sub-header level5"><a href="/pages/258730/#_4-3-2-2-书写功能类" class="sidebar-link">4.3.2.2 书写功能类</a></li><li class="sidebar-sub-header level5"><a href="/pages/258730/#_4-3-2-3-创建测试类目录" class="sidebar-link">4.3.2.3 创建测试类目录</a></li><li class="sidebar-sub-header level5"><a href="/pages/258730/#_4-3-2-4-创建测试包和测试类" class="sidebar-link">4.3.2.4 创建测试包和测试类</a></li><li class="sidebar-sub-header level5"><a href="/pages/258730/#_4-3-2-5-测试方法执行" class="sidebar-link">4.3.2.5 测试方法执行</a></li><li class="sidebar-sub-header level4"><a href="/pages/258730/#_3-3-3-生成测试类" class="sidebar-link">3.3.3 生成测试类</a></li><li class="sidebar-sub-header level4"><a href="/pages/258730/#_3-3-4-测试先行思想" class="sidebar-link">3.3.4 测试先行思想</a></li></ul></li><li class="sidebar-sub-header level2"><a href="/pages/258730/#五、配置文件" class="sidebar-link">五、配置文件</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/pages/258730/#_5-1-前言" class="sidebar-link">5.1 前言</a></li><li class="sidebar-sub-header level3"><a href="/pages/258730/#_5-2-高效的配置文件" class="sidebar-link">5.2 高效的配置文件</a></li><li class="sidebar-sub-header level3"><a href="/pages/258730/#_5-3-properties-文件" class="sidebar-link">5.3 properties 文件</a></li><li class="sidebar-sub-header level4"><a href="/pages/258730/#_5-3-1-语法特点" class="sidebar-link">5.3.1 语法特点</a></li><li class="sidebar-sub-header level4"><a href="/pages/258730/#_5-3-2-使用步骤" class="sidebar-link">5.3.2 使用步骤</a></li><li class="sidebar-sub-header level4"><a href="/pages/258730/#_5-3-3-解析-properties-文件" class="sidebar-link">5.3.3 解析 properties 文件</a></li><li class="sidebar-sub-header level5"><a href="/pages/258730/#_5-3-3-1-properties-类" class="sidebar-link">5.3.3.1 Properties 类</a></li><li class="sidebar-sub-header level5"><a href="/pages/258730/#_5-3-3-2-classloader-类加载器" class="sidebar-link">5.3.3.2 ClassLoader 类加载器</a></li><li class="sidebar-sub-header level5"><a href="/pages/258730/#_5-3-3-3-最终解析" class="sidebar-link">5.3.3.3 最终解析</a></li><li class="sidebar-sub-header level3"><a href="/pages/258730/#_5-4-xml-文件" class="sidebar-link">5.4 xml 文件</a></li><li class="sidebar-sub-header level4"><a href="/pages/258730/#_5-4-1-语法特点" class="sidebar-link">5.4.1 语法特点</a></li><li class="sidebar-sub-header level4"><a href="/pages/258730/#_5-4-2-使用步骤" class="sidebar-link">5.4.2 使用步骤</a></li><li class="sidebar-sub-header level4"><a href="/pages/258730/#_5-4-3-解析-xml-文件" class="sidebar-link">5.4.3 解析 xml 文件</a></li><li class="sidebar-sub-header level5"><a href="/pages/258730/#_5-4-3-1-dom-介绍" class="sidebar-link">5.4.3.1 DOM 介绍</a></li><li class="sidebar-sub-header level5"><a href="/pages/258730/#_5-4-3-2-document-获取-掌握" class="sidebar-link">5.4.3.2 Document 获取（掌握）</a></li><li class="sidebar-sub-header level5"><a href="/pages/258730/#_5-4-3-3-解析案例" class="sidebar-link">5.4.3.3 解析案例</a></li><li class="sidebar-sub-header level5"><a href="/pages/258730/#_5-4-3-4-拓展案例" class="sidebar-link">5.4.3.4 拓展案例</a></li><li class="sidebar-sub-header level5"><a href="/pages/258730/#_5-4-3-5-xml-约束-了解" class="sidebar-link">5.4.3.5 XML 约束（了解）</a></li></ul></li><li class="sidebar-sub-header level2"><a href="/pages/258730/#六、小结与作业" class="sidebar-link">六、小结与作业</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/pages/258730/#_6-1-小结" class="sidebar-link">6.1 小结</a></li><li class="sidebar-sub-header level3"><a href="/pages/258730/#_6-2-作业" class="sidebar-link">6.2 作业</a></li></ul></li></ul></li><li><a href="/pages/1fdc1c/" class="sidebar-link">反射与内省机制</a></li><li><a href="/pages/80d6e3/" class="sidebar-link">Lambda表达式</a></li><li><a href="/pages/a53dcc/" class="sidebar-link">Stream流操作</a></li><li><a href="/pages/42948c/" class="sidebar-link">注解</a></li></ul></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>数据库</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>前端技术</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>热门框架</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>前后端分离</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>权限控制</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>NoSQL</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>微服务</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>消息中间件</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>脚手架</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>技术增值</span> <span class="arrow right"></span></p> <!----></section></li></ul> </aside> <div><main class="page"><div class="theme-vdoing-wrapper "><div class="articleInfo-wrap" data-v-06225672><div class="articleInfo" data-v-06225672><ul class="breadcrumbs" data-v-06225672><li data-v-06225672><a href="/" title="首页" class="iconfont icon-home router-link-active" data-v-06225672></a></li> <li data-v-06225672><a href="/categories/?category=Java%E9%80%9F%E9%80%9A" title="分类" data-v-06225672>Java速通</a></li><li data-v-06225672><a href="/categories/?category=%E5%9F%BA%E7%A1%80%E9%AB%98%E7%BA%A7" title="分类" data-v-06225672>基础高级</a></li></ul> <div class="info" data-v-06225672><div title="作者" class="author iconfont icon-touxiang" data-v-06225672><a href="https://github.com/langfeiyes" target="_blank" title="作者" class="beLink" data-v-06225672>langfeiyes</a></div> <div title="创建时间" class="date iconfont icon-riqi" data-v-06225672><a href="javascript:;" data-v-06225672>2024-03-03</a></div> <!----></div></div></div> <!----> <div class="content-wrapper"><div class="right-menu-wrapper"><div class="right-menu-margin"><div class="right-menu-title">目录</div> <div class="right-menu-content"></div></div></div> <h1><img src="">单元测试与配置文件<!----></h1>  <div class="theme-vdoing-content content__default"><h1 id="单元测试与配置文件"><a href="#单元测试与配置文件" class="header-anchor">#</a> 单元测试与配置文件</h1> <h2 id="一、今日内容与目标"><a href="#一、今日内容与目标" class="header-anchor">#</a> 一、今日内容与目标</h2> <ul><li>理解开发环境统一的重要性</li> <li>掌握 idea 工具的编码设置</li> <li>了解 idea 如何修改快捷键</li> <li>了解软件的生命周期和设计原则</li> <li>掌握并遵循编码命名规范</li> <li>了解 jar 的导出</li> <li>掌握 jar 包的导入</li> <li>掌握单元测试( JUnit )的使用</li> <li>理解什么是硬编码以及配置文件的作用</li> <li>掌握配置文件 propertis 的书写和读取</li> <li>掌握配置文件 xml 的书写</li> <li>了解 xml 文件的解析</li></ul> <h2 id="二、企业开发注意"><a href="#二、企业开发注意" class="header-anchor">#</a> 二、企业开发注意</h2> <h3 id="_2-1-开发环境"><a href="#_2-1-开发环境" class="header-anchor">#</a> 2.1 开发环境</h3> <p><strong>开发环境</strong>：支持软件或应用的开发、运行和维护的一组软件.（JDK、IDEA ...）</p> <p><strong>开发环境使用注意事项</strong>：</p> <ul><li>在团队开发中,需避免环境差异带来的一些问题,避免项目在自己电脑上没问题,别人电脑运行报错的情况.</li> <li>开发环境需要跟项目投入使用的运行环境一致,避免投入使用时出现问题.</li></ul> <p><strong>学习目标</strong>： 注重开发中环境的统一，尽量将环境和老师的环境统一,否则后期可能出现各种配置操作不同甚至产生一些幽灵问题,<code>费力不讨好，浪费时间</code>.</p> <p><strong>大神班使用的开发环境</strong>：</p> <p>开发工具（IDE）： ideaIU-2019.3 版本，简称 idea</p> <p>运行环境：JDK 1.11 环境,简称 JDK11</p> <h3 id="_2-2-idea-配置注意"><a href="#_2-2-idea-配置注意" class="header-anchor">#</a> 2.2 idea 配置注意</h3> <h4 id="_2-2-1-项目编码设置-掌握"><a href="#_2-2-1-项目编码设置-掌握" class="header-anchor">#</a> 2.2.1 项目编码设置(掌握)</h4> <blockquote><p>File  --&gt;  setting  --&gt; Edior --&gt;  File Encodings</p></blockquote> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/2.2-ideaencodingsetting1.png" alt="image-20220328192409211"><br></p> <h4 id="_2-2-2-新项目编码设置"><a href="#_2-2-2-新项目编码设置" class="header-anchor">#</a> 2.2.2 新项目编码设置</h4> <blockquote><p>File --&gt; Other Setting --&gt;  Settings for New Projects --&gt; File Encoding</p></blockquote> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/2.2-ideadefaultencoding2.png" alt="image-20220328192553381"><br></p> <h4 id="_2-2-3-调整字体大小"><a href="#_2-2-3-调整字体大小" class="header-anchor">#</a> 2.2.3 调整字体大小</h4> <blockquote><p>File -&gt; Settings -&gt; Editor -&gt; Color Scheme -&gt; Color Scheme Font-&gt; Size</p></blockquote> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/2.2-frontsetting1.png" alt="image-20220328192743002"><br></p> <h4 id="_2-2-4-设置为-eclipse-快捷键-了解"><a href="#_2-2-4-设置为-eclipse-快捷键-了解" class="header-anchor">#</a> 2.2.4 设置为 eclipse 快捷键(了解)</h4> <p>设置快捷键和 eclipse 工具的快捷键相同（根据个人习惯决定是否设置)</p> <blockquote><p>步骤：</p> <ol><li>File -&gt; Settings -&gt; keymap 选择使用 eclipse 快捷键方式</li> <li>修改代码提示快捷键（默认是 Ctrl + 空格）</li></ol></blockquote> <p>Basic 右键，删除默认快捷键 Ctrl + 空格</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/2.2-ideasettingshortcut1.png" alt="image-20220328193017670"></p> <p><br>Basic 右键，添加新快捷键（增加代码提示快捷键）</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/2.2-ideasettingshortcut2.png" alt="image-20220328193232697"><br></p> <p>填入 Alt + / 提示存在，直接 OK</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/2.2-ideasettingshortcut3.png" alt="image-20220328193358030"><br></p> <p>移除其他 Alt +/ 的设置</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/2.2-ideasettingshortcut4.png" alt="image-20220328193602274"><br></p> <h3 id="_2-3-软件开发概述-了解"><a href="#_2-3-软件开发概述-了解" class="header-anchor">#</a> 2.3 软件开发概述（了解）</h3> <h4 id="_2-3-1-软件的生命周期"><a href="#_2-3-1-软件的生命周期" class="header-anchor">#</a> 2.3.1 软件的生命周期</h4> <p>生命周期： 从立项到软件停用的过程,分以下 6 个环节<br></p> <ol><li><strong>问题的定义及规划</strong>: 开发方与需求方讨论确定软件开发目标及可行性</li> <li><strong>需求分析</strong>: 对软件需实现的各功能进行详细分析。</li> <li><strong>软件设计</strong>: 把软件划分为大大小小的模块，设计每一模块具体结构，并选择框架，数据库使用等。</li> <li><strong>程序编码</strong>: 编写程序代码，在程序编码中必须制定统一，标准的编写规范，以保证程序的可读性，易维护性，提高程序的运行效率。</li> <li><strong>软件测试</strong>: 在软件设计完成后要经过严密的测试并加以纠正。测试过程分单元测试（白盒）、集成测试（黑盒，功能测试、强度性能测试）以及系统测试三个阶段进行。测试过程中需建立详细的测试计划并严格按照测试计划进行测试，以减少测试的随意性。</li> <li><strong>运行维护</strong>: 安装部署软件系统，修复软件中存在的bug和升级系统。为适应用户要求对软件进行改进性维护和纠错性维护。</li></ol> <h4 id="_2-3-2-软件设计原则"><a href="#_2-3-2-软件设计原则" class="header-anchor">#</a> 2.3.2 软件设计原则</h4> <p>为提高软件的开发效率，降低软件开发成本，一个优良的软件系统应具有以下特点：</p> <ol><li><strong>可重用性</strong>：遵循 DRY 原则，减少软件中的重复代码。</li> <li><strong>可拓展性</strong>：当软件需要升级增加新的功能，能够在现有的系统架构上方便地创建新的模块，而不需要改变软件现有的结构，也不会影响已经存在的模块。</li> <li><strong>可维护性</strong>：当用户需求发生变化时，只需要修改局部的模块中的少量代码即可</li></ol> <p><code>如何让软件达到上述特点？</code>需对模块的要求：</p> <ol><li><p>结构稳定性：在软件设计阶段，把一个模块划分为更小的模块时，设计合理，使得系统结构健壮，以便适应用户的需求变化。</p></li> <li><p>可拓展性：当软件必须增加新的功能时，可在现有模块的基础上创建出新的模块，该模块继承了原有模块的一些特性，并且还具有一些新的特性，从而实现软件的可重用和可拓展性。</p></li> <li><p>可组合性：若干模块经过组合，形成大系统，模块的可组合性提高软件的可重用和可维护性，并且能简化软件开发过程。</p></li> <li><p><strong>高内聚性</strong>：内聚，强调一个系统模块内的功能联系，每个模块只完成特定的功能，不同模块之间不会有功能的重叠，高内聚性可以提高软件的可重用性和可维护性。</p></li> <li><p><strong>低耦合性</strong>：耦合，强调的是多个模块之间的关系，模块之间相互独立，修改某一个模块，不会影响到其他的模块。低耦合性提高了软件的可维护性。</p></li></ol> <h3 id="_2-4-编码规范"><a href="#_2-4-编码规范" class="header-anchor">#</a> 2.4 编码规范</h3> <h4 id="_2-4-1-为什么要有规范"><a href="#_2-4-1-为什么要有规范" class="header-anchor">#</a> 2.4.1 为什么要有规范？</h4> <p><a href="https://blog.csdn.net/csdnsevenn/article/details/82838914" target="_blank" rel="noopener noreferrer">美国程序员枪击案<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> <a href="https://zhuanlan.zhihu.com/p/70495300" target="_blank" rel="noopener noreferrer">写出无法维护的代码<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></p> <h4 id="_2-4-2-alibaba-开发手册"><a href="#_2-4-2-alibaba-开发手册" class="header-anchor">#</a> 2.4.2 Alibaba 开发手册</h4> <p><a href="%E8%B5%84%E6%96%99/%E9%98%BF%E9%87%8C%E5%B7%B4%E5%B7%B4Java%E5%BC%80%E5%8F%91%E6%89%8B%E5%86%8C(%E7%BB%88%E6%9E%81%E7%89%88).pdf">阿里巴巴Java开发手册(终极版).pdf</a></p> <p>​	本手册的愿景是  <strong>码出高效，码出质量</strong>。现代软件架构都需要协同开发完成，高效协作即降低协同成本，提升沟通效率，所谓无规矩不成方圆，无规范不能协作。众所周知，制订交通法规表面上是要限制行车权，实际上是保障公众的人身安全。试想如果没有限速，没有红绿灯，谁还敢上路行驶。对软件来说，适当的规范和标准绝不是消灭代码内容的创造性、优雅性，而是限制过度个性化，以一种普遍认可的统一方式一起做事，提升协作效率。代码的字里行间流淌的是软件生命中的血液，质量的提升是尽可能少踩坑，杜绝踩重复的坑，切实提升质量意识。</p> <p><strong>对于团队的协作</strong>开发。必须要有规范。<strong>对于程序员来说，没有规范，就是灾难</strong>。</p> <h4 id="_2-4-3-sun-规范要求"><a href="#_2-4-3-sun-规范要求" class="header-anchor">#</a> 2.4.3 SUN 规范要求</h4> <p>编码规范对于程序员而言尤为重要，有以下几个原因：</p> <ol><li>一个软件的生命周期中，80% 的时间花费在于维护.</li> <li>几乎没有任何一个软件，在其整个生命周期中，均由最初的开发人员来维护。</li> <li>编码规范可以改善软件的可读性，可以让程序员尽快而彻底地理解新的代码。</li></ol> <p>所以为了执行规范，每个软件开发人员必须一致遵守编码规范。</p> <h4 id="_2-4-5-呕心沥血整理的规范"><a href="#_2-4-5-呕心沥血整理的规范" class="header-anchor">#</a> 2.4.5 呕心沥血整理的规范</h4> <p><strong>基本命名规范</strong>：使用有意义的英文单词，多个单词用驼峰表示法。</p> <table><thead><tr><th>起名项</th> <th>要求</th> <th>例子</th></tr></thead> <tbody><tr><td><code>包名</code></td> <td>全小写：域名倒写.模块名.组件名</td> <td>cn.wolfcode.crm.util</td></tr> <tr><td><code>接口名</code></td> <td>首字母大写，形容词，副词。<br>习惯以  <strong>I</strong>  开头，I表示 interface,见名知意.<br>(不强制,要结合其他规范综合考虑)</td> <td>IUserService、IEmployeeService</td></tr> <tr><td><code>接口实现类</code></td> <td>习惯性使用 <strong>Impl</strong> 结尾<br>(不强制,要结合其他规范综合考虑)</td> <td>UserServiceImpl、EmployeeServiceImpl</td></tr> <tr><td><code>类名</code></td> <td>首字母大写，名词，遵循驼峰表示法</td> <td>User、Employee</td></tr> <tr><td><code>方法名</code></td> <td>首字母小写，力求语义清晰，<br>多个单词，遵循驼峰表示法</td> <td>getUserInfoByName()、checkUsername()</td></tr> <tr><td><code>变量名</code></td> <td>首字母小写，力求语义清晰，<br>多个单词，遵循驼峰表示法</td> <td>userInfo、userId、username、password</td></tr> <tr><td><code>常量名</code></td> <td>全大写，力求语义清晰，<br>多个单词，使用下划线分割</td> <td>MAX_STOCK_COUNT <br>适用 public static final 修饰的常量</td></tr></tbody></table> <h4 id="_2-4-6-高薪秘诀"><a href="#_2-4-6-高薪秘诀" class="header-anchor">#</a> 2.4.6 高薪秘诀</h4> <ol><li>从今天开始写代码必须遵循规范，无规范无高薪。</li> <li><code>跟这个存哥走，面包牛奶都会有</code>。</li></ol> <h2 id="三、jar-包使用"><a href="#三、jar-包使用" class="header-anchor">#</a> 三、Jar 包使用</h2> <blockquote><p>之前使用 JDK 内置的工具类，比如 Arrays，Collections 等,是直接 import 就可以使用,那如果咱们也想像 JDK 一样写一些工具类给别人项目使用,该如何操作？</p> <p><strong>方案</strong>：将写好的工具类打成 jar 包，然后在需要用工具的项目上引入该 jar 包</p></blockquote> <p><strong>jar 包</strong>：将多个 class 文件打成的压缩包，为 jar 包，可直接运行也可作为其他项目的工具使用。</p> <h3 id="_3-1-jar-导出"><a href="#_3-1-jar-导出" class="header-anchor">#</a> 3.1 jar 导出</h3> <p>1 创建项目，准备工具类和工具方法</p> <div class="language-JAVA line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">StringUtil1</span><span class="token punctuation">{</span>
  <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">boolean</span> <span class="token function">hasLength</span><span class="token punctuation">(</span><span class="token class-name">String</span> val<span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token keyword">return</span> val <span class="token operator">!=</span> <span class="token keyword">null</span> <span class="token operator">&amp;&amp;</span> <span class="token operator">!</span><span class="token string">&quot;&quot;</span><span class="token punctuation">.</span><span class="token function">equals</span><span class="token punctuation">(</span>val<span class="token punctuation">.</span><span class="token function">trim</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">StringUtil2</span><span class="token punctuation">{</span>
  <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">boolean</span> <span class="token function">hasLength</span><span class="token punctuation">(</span><span class="token class-name">String</span> val<span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token keyword">return</span> val <span class="token operator">!=</span> <span class="token keyword">null</span> <span class="token operator">&amp;&amp;</span> <span class="token operator">!</span><span class="token string">&quot;&quot;</span><span class="token punctuation">.</span><span class="token function">equals</span><span class="token punctuation">(</span>val<span class="token punctuation">.</span><span class="token function">trim</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">StringUtil3</span><span class="token punctuation">{</span>
  <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">boolean</span> <span class="token function">hasLength</span><span class="token punctuation">(</span><span class="token class-name">String</span> val<span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token keyword">return</span> val <span class="token operator">!=</span> <span class="token keyword">null</span> <span class="token operator">&amp;&amp;</span> <span class="token operator">!</span><span class="token string">&quot;&quot;</span><span class="token punctuation">.</span><span class="token function">equals</span><span class="token punctuation">(</span>val<span class="token punctuation">.</span><span class="token function">trim</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br></div></div><br> <p>2 将项目导出为 jar 包,供其他项目使用</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/2.2-jarpkg2.png" alt="jar包2"><br></p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/2.2-jarpkg3.png" alt="image-20220328200958102"><br><br><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/2.2-jarpkg4.png" alt="jar包4"><br><br></p> <p>弹出框位置查看 jar 的存放位置,<strong>拷贝路径</strong></p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/2.2-jarpkg5.png" alt="image-20220328201247043"><br></p> <p>在 Build 中去生成 jar 包到指定目录下.</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/2.2-jarpkg6.png" alt="image-20220328201420981"><br></p> <p>在上步拷贝的路径下拷贝 jar 包。</p> <h3 id="_3-2-jar-导入"><a href="#_3-2-jar-导入" class="header-anchor">#</a> 3.2  jar 导入</h3> <p>将刚导出的 jar 文件拷贝到新项目的 lib 目录下并引用</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/2.2-jarpkg7.png" alt="jar包7"><br></p> <p>使用 jar 包中的功能</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">App</span><span class="token punctuation">{</span>
  <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token class-name">String</span> str <span class="token operator">=</span> <span class="token string">&quot;存哥&quot;</span><span class="token punctuation">;</span>
    <span class="token comment">// 判断字符串是否为空</span>
    <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token class-name">StringUtil</span><span class="token punctuation">.</span><span class="token function">hasLength</span><span class="token punctuation">(</span>str<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><p><code>如果以后需要使用别人写好的功能,就只需要拷贝别人的 jar 包到自己的项目中,然后引用就可以使用 jar 包中的功能.</code></p> <h2 id="四、软件测试"><a href="#四、软件测试" class="header-anchor">#</a> 四、软件测试</h2> <h3 id="_4-1-软件测试概述-了解"><a href="#_4-1-软件测试概述-了解" class="header-anchor">#</a> 4.1 软件测试概述(了解)</h3> <p>在软件生命周期中，测试是一个重要的环节，从编码开始，甚至可能早于编码就已经进入了软件生命周期 。<strong>而且一款优秀的软件,不是开发出来的,而是测试出来的</strong>. 一个软件是否开发完毕，并不是开发工程师说了算，而是测试工程师说了算，因为只有经过精密测试后的软件才能上线使用。</p> <h3 id="_4-2-测试分类-了解"><a href="#_4-2-测试分类-了解" class="header-anchor">#</a> 4.2 测试分类(了解)</h3> <p>站在是否能够看到代码或者是否需要写代码的角度将软件测试分为以下两类。</p> <h4 id="_4-2-1-黑盒测试"><a href="#_4-2-1-黑盒测试" class="header-anchor">#</a> 4.2.1 黑盒测试</h4> <p>黑盒测试也称功能测试，是通过测试来检测每个功能是否能正常使用，把程序看作一个不能打开的黑盒子，在完全不考虑程序内部结构和内部特性的情况下，在程序的接口上进行测试，检查程序功能是否 <strong>按照需求规格说明书</strong> 的规定正常使用。</p> <p><code>*结论： 手动测试，不用写代码</code></p> <p><strong>作用</strong>：主要试图发现下列几类错误</p> <ul><li>功能是否不正确或遗漏；</li> <li>界面是否有错误；</li> <li>输入和输出错误；</li> <li>数据库访问错误；</li> <li>性能是否有问题；</li> <li>初始化和终止错误等</li></ul> <h4 id="_4-2-2-白盒测试"><a href="#_4-2-2-白盒测试" class="header-anchor">#</a> 4.2.2 白盒测试</h4> <p><strong>由开发人员来测试</strong>，又称结构测试、透明盒测试、逻辑驱动测试或  <strong>基于代码</strong> 的测试。
它是按照程序内部的结构测试程序，通过测试来检测产品内部动作是否按照设计规格说明书的规定正常执行。测试者必须检查程序的内部结构，从检查程序的逻辑着手，得出测试数据。</p> <p><code>*结论：代码测试，需要写代码</code></p> <p><strong>作用</strong>：主要做以下代码测试</p> <ul><li><p>检查程序内部结构是否存在遗漏；</p></li> <li><p>程序功能是否完成；</p></li> <li><p>程序功能是否有错；</p></li> <li><p>程序功能是否按规格说明书实现</p></li></ul> <p><code>而作为 Java 攻城狮，白盒测试是离不开的，所以为了更高效的写代码做做白盒测试，接下来需要来学习单元测试框架JUnit</code></p> <h3 id="_4-3-单元测试-junit-掌握"><a href="#_4-3-单元测试-junit-掌握" class="header-anchor">#</a> 4.3 单元测试 JUnit（掌握）</h3> <p>JUnit 是由 Erich Gamma 和 Kent Beck 编写的一个回归测试框架（regression testing framework）。JUnit 测试是程序员测试，即所谓白盒测试，因为程序员知道被测试的软件如何（How）完成功能和完成什么样（What）的功能。
官网：http://www.junit.org/</p> <p>Java 的单元测试 JUnit 存在三个版本</p> <ol><li>junit3.x   针对于 Java5 之前的版本, android 中使用，不推荐.</li> <li>junit4.x   针对于 Java5 以及之后的版本,使用注解,推荐.</li> <li>junit5.x   针对于 Java8 以及以后的版本.</li></ol> <h4 id="_4-3-1-为什么需要-junit"><a href="#_4-3-1-为什么需要-junit" class="header-anchor">#</a> 4.3.1 为什么需要 JUnit</h4> <p>目前我们实现完一个功能需要进行测试，比如要测试 Person 类中的 work 方法.代码如下。</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/junit1.png" alt=""><br></p> <p>需要创建一个测试类，然后在主方法中来书写测试代码。</p> <p><strong>问题</strong>：如果有100个方法需要测试，就需要创建 100 个测试类，然后在main方法中书写测试代码，去创建对象，调用方法。非常麻烦，类文件也会很多。而要保证每个功能的修改都能马上执行测试，目前实现太繁琐。</p> <p><code>怎么办？？？ 使用 JUnit 单元测试框架来实现测试代码的管理</code></p> <h4 id="_4-3-2-junit4-使用步骤"><a href="#_4-3-2-junit4-使用步骤" class="header-anchor">#</a> 4.3.2 JUnit4 使用步骤</h4> <h5 id="_4-3-2-1-junit-4-依赖安装"><a href="#_4-3-2-1-junit-4-依赖安装" class="header-anchor">#</a> 4.3.2.1 JUnit 4 依赖安装</h5> <p>由于 JUnit4 回归测试框架是三方提供的，不是 JDK 自带的，所以使用需导入人家的 jar 包以及安装对应的插件</p> <blockquote><p>Idea 插件安装：File -&gt; Settings -&gt; Plugins -&gt; 搜索 junit ，默认是自带的，没有的在此处安装。</p></blockquote> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/2.2-ideaJunitpluginsinstall.png" alt="image-20220331160339269"><br></p> <p>jar 包可以直接拷贝进项目，也可能等后续用 idea 导入。</p> <h5 id="_4-3-2-2-书写功能类"><a href="#_4-3-2-2-书写功能类" class="header-anchor">#</a> 4.3.2.2 书写功能类</h5> <p>书写带有需要被测试的功能类和功能方法</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">UserDAOImpl</span><span class="token punctuation">{</span>
  <span class="token comment">// 添加功能模拟</span>
  <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">add</span><span class="token punctuation">(</span><span class="token class-name">String</span> username<span class="token punctuation">,</span><span class="token class-name">String</span> password<span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;添加用户：&quot;</span> <span class="token operator">+</span> username <span class="token operator">+</span> <span class="token string">&quot; 密码为：&quot;</span> <span class="token operator">+</span> password<span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
  <span class="token comment">// 删除功能模拟</span>
  <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">delete</span><span class="token punctuation">(</span><span class="token class-name">Long</span> sn<span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;删除学号为&quot;</span> <span class="token operator">+</span> sn <span class="token operator">+</span> <span class="token string">&quot;的学生&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br></div></div><h5 id="_4-3-2-3-创建测试类目录"><a href="#_4-3-2-3-创建测试类目录" class="header-anchor">#</a> 4.3.2.3 创建测试类目录</h5> <p>创建一个普通文件夹 test</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/2.2-ideaJUnitTestdir1.png" alt="image-20220331155231292"><br></p> <p>将普通目录 test 改为测试目录(Test Soruces Root)</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/2.2-ideaJUnitTestdir2.png" alt=""><br></p> <h5 id="_4-3-2-4-创建测试包和测试类"><a href="#_4-3-2-4-创建测试包和测试类" class="header-anchor">#</a> 4.3.2.4 创建测试包和测试类</h5> <p>创建包：cn.wolfcode.junitdemo.test 并创建测试类 UserDAOTest ，编写测试方法，格式如下：</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">UserDAOTest</span><span class="token punctuation">{</span>
	<span class="token annotation punctuation">@Test</span>
	<span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">testXxx</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token keyword">throws</span> <span class="token class-name">Exception</span> <span class="token punctuation">{</span>
	<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><p><code>注意: 测试方法必须是 public 修饰、无参、无返回并且贴有 @Test 标签的, Xxx 表示测试的功能方法名字.</code></p> <p>测试代码书写：</p> <div class="language-JAVA line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">UserDAOImplTest</span><span class="token punctuation">{</span>
  <span class="token comment">// 引入要测试的类</span>
  <span class="token keyword">private</span> <span class="token class-name">UserDAOImpl</span> userDAO <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">UserDAOImpl</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  
  <span class="token comment">// 功能方法对应的测试代码编写</span>
  <span class="token annotation punctuation">@Test</span>
  <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">add</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
    userDAO<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token string">&quot;存哥&quot;</span><span class="token punctuation">,</span><span class="token string">&quot;123456&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
  
  <span class="token annotation punctuation">@Test</span>
  <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">delete</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
    userDAO<span class="token punctuation">.</span><span class="token function">delete</span><span class="token punctuation">(</span><span class="token number">11L</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br></div></div><p><code>在 @Test 按提示快捷键 Alt+Enter ，导入 JUnit4 的依赖包</code></p> <h5 id="_4-3-2-5-测试方法执行"><a href="#_4-3-2-5-测试方法执行" class="header-anchor">#</a> 4.3.2.5 测试方法执行</h5> <p>选择某一个测试方法，鼠标右键选择  run testXxx()，或点击方法前的绿色三角形</p> <p>或者选中测试类,表示执行该类中所有的测试方法。</p> <p><strong>选中方法，右键运行</strong></p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/2.2-ideajunittest.png" alt=""></p> <h4 id="_3-3-3-生成测试类"><a href="#_3-3-3-生成测试类" class="header-anchor">#</a> 3.3.3 生成测试类</h4> <blockquote><p>选中要测试的<strong>类名</strong> Alt + Enter -&gt; Create Test (<a href="https://www.jianshu.com/p/7f8d512469b9" target="_blank" rel="noopener noreferrer">无 Create Test 解决<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>)</p></blockquote> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/2.2-ideacreatetestclass.png" alt=""><br></p> <p>项目首次使用 JUnit，需要点击 Fix 导入 JUnit 包。</p> <h4 id="_3-3-4-测试先行思想"><a href="#_3-3-4-测试先行思想" class="header-anchor">#</a> 3.3.4 测试先行思想</h4> <p>在你不知道如何测试代码前,就不要写代码去完成功能. -- <strong>测试先行</strong> （marting flower）</p> <p>除非测试成功，否则你不能认为你编写出了可以工作的程序.</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/2.2-martingFlower.png" alt="marting Flower.png"><br></p> <h2 id="五、配置文件"><a href="#五、配置文件" class="header-anchor">#</a> 五、配置文件</h2> <h3 id="_5-1-前言"><a href="#_5-1-前言" class="header-anchor">#</a> 5.1 前言</h3> <p>以前开发中，存一些数据是直接在代码的变量中来实现的，但如果变量的值偶尔需要修改，就需要修改 java 文件中的代码，然后编译成 class 文件才能使用上功能，这样非常的麻烦。而编写存了偶尔需要修改的数据的代码称为硬编码。</p> <p><strong>例子</strong>：用 Java 程序去连接其他程序，比如数据库，需要使用账号和密码，此时我们是使用两个变量来记录：如下</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">private</span> <span class="token class-name">String</span> username <span class="token operator">=</span> <span class="token string">&quot;root&quot;</span><span class="token punctuation">;</span>
<span class="token keyword">private</span> <span class="token class-name">String</span> password <span class="token operator">=</span> <span class="token string">&quot;admin&quot;</span><span class="token punctuation">;</span>	
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p>想要使用账号和密码,直接重复使用两个变量即可.</p> <p><strong>问题</strong>： 账号和密码是直接写死在程序中的，如果数据库的账号密码改了，此时就需要修改代码，然后编译等才能使用，非常繁琐，工作量也大，不利运维人员运行项目，而存账号密码数据的代码则为 <strong>硬编码</strong>。</p> <p><strong>如何解决硬编码?</strong></p> <p>可以把这些需要修改的内容写在一个普通的文件中，然后在程序中读取文件内容，以后修改只需修改普通文件即可。</p> <p><strong>例</strong>：用 user.txt   存入</p> <p>username=rootpassword=admin</p> <p>而这种存了数据给程序使用的文件称为<code>配置文件</code>。</p> <h3 id="_5-2-高效的配置文件"><a href="#_5-2-高效的配置文件" class="header-anchor">#</a> 5.2 高效的配置文件</h3> <p>按理说只要能保存一些配置信息，供程序动态读取数据就OK，但是为了提高效率，统一格式，在 IT 行业中，习惯使用两种具有特殊特点的文件来作为配置文件，分别是 <strong>properties 文件 和 XML 文件</strong></p> <h3 id="_5-3-properties-文件"><a href="#_5-3-properties-文件" class="header-anchor">#</a> 5.3 properties 文件</h3> <p>拓展名为 .properties 的文件称为属性文件/资源文件/配置文件</p> <h4 id="_5-3-1-语法特点"><a href="#_5-3-1-语法特点" class="header-anchor">#</a> 5.3.1 语法特点</h4> <p><strong>存数据特点</strong></p> <blockquote><p>key=value 格式，多对数据使用换行分开</p></blockquote> <p>user.properties</p> <div class="language-properties line-numbers-mode"><pre class="language-properties"><code><span class="token key attr-name">username</span><span class="token punctuation">=</span><span class="token value attr-value">root</span>
<span class="token key attr-name">password</span><span class="token punctuation">=</span><span class="token value attr-value">admin</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p><strong>使用注意事项</strong>：</p> <p>1.配置文件是给类去读取的，所以需要跟随着字节码走.需要放在 Resources Root 类型的目录中，会直接拷贝到字节码输出路径。</p> <p>2 在配置文件中，所有的数据都是字符串，不需要使用引号，注释用 ## 号。</p> <p>3 在配置文件中不需要使用空格。</p> <h4 id="_5-3-2-使用步骤"><a href="#_5-3-2-使用步骤" class="header-anchor">#</a> 5.3.2 使用步骤</h4> <p>1 创建普通文件夹 resources</p> <p>2 将文件夹改为 Resources Root 目录（内部文件会被拷贝到字节码根路径下）</p> <p>3 在目录中创建配置文件</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/2.2-ideaJUnitTest-1708160458906.png" alt="image-20220331155231292"><br></p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/2.2-properties2.png" alt="image-20220331174257685"></p> <p>4 在 resources 目录下创建文件，命名为 user.properties，内容如下：</p> <div class="language-properties line-numbers-mode"><pre class="language-properties"><code><span class="token key attr-name">username</span><span class="token punctuation">=</span><span class="token value attr-value">root</span>
<span class="token key attr-name">password</span><span class="token punctuation">=</span><span class="token value attr-value">admin</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p>至此有了配置文件，接下来就是在代码中读取配置文件中的数据，那要<code>如何读取呢？</code></p> <p>其实想要读取 properties 中的数据，咱们使用 IO 操作，一行一行的读取，再通过 &quot;=&quot; 来拆分字符串也可以完成。但是这个过程还是比较麻烦的，如果有注释更麻烦，<code>那肿么办？</code>。</p> <p><strong>意识</strong>: 如果一个操作非常复杂,自己实现非常麻烦，而很多人都需要这个功能，这个时候一般会有人提供好的工具来实现该功能。其实 SUN 公司已经提供好了读取 properties 文件数据的工具方法。就是 Properties 类中的 load() 实例方法。</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/2.2-properties3.png" alt=""><br></p> <h4 id="_5-3-3-解析-properties-文件"><a href="#_5-3-3-解析-properties-文件" class="header-anchor">#</a> 5.3.3 解析 properties 文件</h4> <h5 id="_5-3-3-1-properties-类"><a href="#_5-3-3-1-properties-类" class="header-anchor">#</a> 5.3.3.1 Properties 类</h5> <p>Properties 是 Map 的实现类，继承 Map 的所有操作方法(get,put....)，但 Map 中的方法，咱们一般不用。因为 properties 文件比较特殊，存的都是字符串，所以使用 Properties 类新增的方法.</p> <p><strong>常用的 API</strong></p> <blockquote><p>public void load(InputStream inStream);    // 通过输入流加载配置文件中的内容.</p> <p>public String getProperty(String key);        // 通过属性名获取属性值</p></blockquote> <p><strong>数据解析代码</strong></p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">ParseFileTest</span><span class="token punctuation">{</span>
	<span class="token annotation punctuation">@Test</span>
	<span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">testParseProperties</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
 		<span class="token comment">// 1 使用 IO 将配置文件转为输入流</span>
  	<span class="token class-name">InputStream</span> is <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">FileInputStream</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">File</span><span class="token punctuation">(</span><span class="token string">&quot;E:/ideaSpace/day01-基础加强/resources/user.properties&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  
  	<span class="token class-name">Properties</span> p <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Properties</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  	<span class="token comment">// 2 用 load 方法解析文件内容</span>
  	p<span class="token punctuation">.</span><span class="token function">load</span><span class="token punctuation">(</span>is<span class="token punctuation">)</span><span class="token punctuation">;</span>
  
  	<span class="token comment">// 3 从 Properties 对象中获取解析出来的数据</span>
  	<span class="token class-name">String</span> username <span class="token operator">=</span> p<span class="token punctuation">.</span><span class="token function">getProperty</span><span class="token punctuation">(</span><span class="token string">&quot;username&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  	<span class="token class-name">String</span> password <span class="token operator">=</span> p<span class="token punctuation">.</span><span class="token function">getProperty</span><span class="token punctuation">(</span><span class="token string">&quot;username&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  	<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>username <span class="token operator">+</span> <span class="token string">&quot;,&quot;</span> <span class="token operator">+</span> password<span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br></div></div><p>上面代码，使用了绝对路径，在开发中绝对不能使用。因为以后项目会移动，路径会被改动，只能使用相对路径。</p> <p><strong>由于配置文件跟着字节码走，所以可以相对于字节码根路径来读取文件</strong></p> <h5 id="_5-3-3-2-classloader-类加载器"><a href="#_5-3-3-2-classloader-类加载器" class="header-anchor">#</a> 5.3.3.2 ClassLoader 类加载器</h5> <p>JDK 自带类 ClassLoader  中有个实例方法 getResourceAsStream()，可以从字节码根路径下读取文件转为输入流。</p> <p><strong>获取 ClassLoader 对象的两种方式</strong>：</p> <ul><li>某个类名.class.getClassLoader()  : ParseFileTest.class.getClassLoader() 类名字带动代码则失效，功能受限于使用的类。</li> <li>Thread.currentThread().getContextClassLoader() : 推荐使用，直奔主题获取对象。</li></ul> <h5 id="_5-3-3-3-最终解析"><a href="#_5-3-3-3-最终解析" class="header-anchor">#</a> 5.3.3.3 最终解析</h5> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">ParseFileTest</span><span class="token punctuation">{</span>
	<span class="token annotation punctuation">@Test</span>
	<span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">testParseProperties</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token comment">// 1 从字节码输出路径读取文件转为输入流，供 Properties 的 load 方法使用</span>
    <span class="token class-name">ClassLoader</span> classLoader <span class="token operator">=</span> <span class="token class-name">Thread</span><span class="token punctuation">.</span><span class="token function">currentThread</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getContextClassLoader</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token class-name">InputStream</span> is <span class="token operator">=</span> classLoader<span class="token punctuation">.</span><span class="token function">getResourceAsStream</span><span class="token punctuation">(</span><span class="token string">&quot;user.properties&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  
  	<span class="token class-name">Properties</span> p <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Properties</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  	<span class="token comment">// 2 用 load 方法解析配置文件中的内容</span>
  	p<span class="token punctuation">.</span><span class="token function">load</span><span class="token punctuation">(</span>is<span class="token punctuation">)</span><span class="token punctuation">;</span>
  
  	<span class="token comment">// 3 从 Properties 对象中获取解析出来的数据</span>
  	<span class="token class-name">String</span> username <span class="token operator">=</span> p<span class="token punctuation">.</span><span class="token function">getProperty</span><span class="token punctuation">(</span><span class="token string">&quot;username&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  	<span class="token class-name">String</span> password <span class="token operator">=</span> p<span class="token punctuation">.</span><span class="token function">getProperty</span><span class="token punctuation">(</span><span class="token string">&quot;username&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  	<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>username <span class="token operator">+</span> <span class="token string">&quot;,&quot;</span> <span class="token operator">+</span> password<span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br></div></div><h3 id="_5-4-xml-文件"><a href="#_5-4-xml-文件" class="header-anchor">#</a> 5.4 xml 文件</h3> <p><strong>XML</strong>(eXtensible Markup Language)，是一种 <strong>可扩展的标记语言</strong>( 使用 &lt;&gt; 括起来 )，设计宗旨是传输数据。</p> <p>XML 结构清晰(树状结构)，不仅让人能够明白，还让计算机也能够明白，是一种公订的、开放的标准，不受知识产权的限制。一般作为配置文件的存在, 用来传输数据。</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/2.2-xml2.png" alt=""><br></p> <h4 id="_5-4-1-语法特点"><a href="#_5-4-1-语法特点" class="header-anchor">#</a> 5.4.1 语法特点</h4> <p>以 .xml 结尾的文件，该文件是否书写正确，可以使用浏览器打开.</p> <div class="language-xml line-numbers-mode"><pre class="language-xml"><code><span class="token prolog">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;</span>
<span class="token comment">&lt;!-- 以上文档声明，versino:版本，
encoding 编码格式：文档内容编码和文件本身编码必须保持一致--&gt;</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>contacts</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>linkman</span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>1<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>name</span><span class="token punctuation">&gt;</span></span>小狼<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>name</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>email</span><span class="token punctuation">&gt;</span></span>cun@wolfcode.cn<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>email</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>address</span><span class="token punctuation">&gt;</span></span>广州<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>address</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>group</span><span class="token punctuation">&gt;</span></span>Java学院<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>group</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>linkman</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>linkman</span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>2<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>name</span><span class="token punctuation">&gt;</span></span>存哥<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>name</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>email</span><span class="token punctuation">&gt;</span></span>willie@wolfcode.cn<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>email</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>address</span><span class="token punctuation">&gt;</span></span>广州<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>address</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>group</span><span class="token punctuation">&gt;</span></span>Java学院<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>group</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>linkman</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>contacts</span><span class="token punctuation">&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br></div></div><p><strong>语法要求：</strong></p> <ol><li>xml 文档需在文档第一行做声明，声明表示该文档为 xml 文档
<ol><li><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?&gt;</code></li> <li>version: xml 的版本 （了解）</li> <li>standalone：yes 为不可包含其他文档，no或不写表示可包含也可不包含（了解）</li> <li>encoding：编码格式，文档内容的编码和文件的编码需要统一(UTF-8)（<strong>重要</strong>）</li></ol></li> <li>&lt;&gt;  表示 XML 文档中的元素/标签（Element）</li> <li>标签有内容需成对出现，开始标签 <code>&lt;ooxx&gt;</code>,结束标签 <code>&lt;/ooxx&gt;</code></li> <li>标签如果没内容可使用单标签 <code>&lt;ooxx/&gt;</code></li> <li>标签中可以带有属性，格式： 属性名=“属性值” ，id=&quot;1&quot;</li> <li>在 XML 文档中，有且仅有一个根标签</li> <li>在 XML 中，严格区分大小写 <code>&lt;name&gt;</code> -- <code>&lt;Name&gt;</code></li> <li>在 XML 中，允许标签嵌套，但是不允许交叉嵌套</li> <li>在 XML 中，注释使用  </li></ol> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/xml4.png" alt=""></p> <p><strong>常见错误</strong>：</p> <p>1.文档内容和文件本身编码格式一定要为 UTF-8</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/2.2-xmlerr1.png" alt="image-20220331200355630"><br></p> <p>2.严格区分大小写</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/2.2-xmlerr2.png" alt="image-20220331200541363"><br></p> <p>3.有且仅有一个标签直接属于XML文档.即根标签</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/2.1-xmlerr4.png" alt="image-20220331200708993"><br></p> <h4 id="_5-4-2-使用步骤"><a href="#_5-4-2-使用步骤" class="header-anchor">#</a> 5.4.2 使用步骤</h4> <ol><li>创建 xml 文件并按语法填写数据（使用 contacts.xml）</li> <li>使用 JDK 内置的 API 解析 xml  文件中的内容</li></ol> <h4 id="_5-4-3-解析-xml-文件"><a href="#_5-4-3-解析-xml-文件" class="header-anchor">#</a> 5.4.3 解析 xml 文件</h4> <p>通过 xml 层次结构整理如下图：</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/2.2-xmlstruct.png" alt=""><br></p> <p>XML 最终是需要读取到程序保存到内存中的.而从面相对象的角度来思考,</p> <p>XML 的各个组成部分都需要使用一个类型来描述.</p> <ol><li><strong>XML 文件</strong>：把 XML 文档加载到内存中,使用 Document 对象来描述整个文档.</li> <li><strong>标签/元素</strong>：所有的标签,使用 Element 对象来描述.</li> <li><strong>属性</strong>：标签的属性,使用 Attribute 来描述.</li> <li><strong>文本</strong>：文本内容（文本/空格·回车）使用 Text 来描述.</li></ol> <p>根据上面四种成员的共性,继续抽象出父类:org.w3c.dom.Node.所以说，在XML中,一切皆节点.</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/2.2-DOMextends.png" alt=""><br></p> <p>而这种把 XML 文档加载到内存之后，形成一个一个的对象，这种操作我们称为 <strong>DOM 解析</strong>。</p> <h5 id="_5-4-3-1-dom-介绍"><a href="#_5-4-3-1-dom-介绍" class="header-anchor">#</a> 5.4.3.1 DOM 介绍</h5> <p><strong>DOM</strong>: Document Object Model: 文档对象模型,把文档中的成员描述成一个个对象.</p> <p><strong>后期使用场景</strong>： 使用 JavaScript (js) 来解析 HTML 中的数据.</p> <p><strong>特点</strong>:
在加载的时候,一次性把整个 XML文档加载进内存,在内存中形成一颗树(<strong>Document对象</strong>)/<strong>DOM树</strong>.
我们以后使用代码操作 Document,其实操作的是内存中的 DOM树,和本地磁盘中的XML文件没有直接关系.
比如: 保存了一个联系人, 仅仅是内存中多了一个联系人,但是在XML文件中没有新增的痕迹.
除非做  同步操作(把内存中的数据更新到XML文件).-----&gt; 增删改操作完之后,都需要做同步操作.</p> <p><strong>缺点</strong>:  若 XML 文件过大,可能造成内存溢出.
操作 XML 的增删改查(CRUD)的时候很简单,但是性能比较低下.</p> <h5 id="_5-4-3-2-document-获取-掌握"><a href="#_5-4-3-2-document-获取-掌握" class="header-anchor">#</a> 5.4.3.2 Document 获取（掌握）</h5> <p>XML 被程序读到内存中会形成一个 Document 对象，所有要解析 XML ，首先得先获取到 Document 对象</p> <p>获取文档 Document 对象的步骤:</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token comment">// 1.声明文件 xml 文件</span>
<span class="token class-name">File</span> file <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">File</span><span class="token punctuation">(</span>path<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 2.通过 DocumentBuilderFactory 的 newInstance 方法获取本身的对象</span>
<span class="token class-name">DocumentBuilderFactory</span> factory <span class="token operator">=</span>  <span class="token class-name">DocumentBuilderFactory</span><span class="token punctuation">.</span><span class="token function">newInstance</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 3.通过 DocumentBuilderFactory 对象去获取 DocumentBuilder 对象</span>
<span class="token class-name">DocumentBuilder</span> builder <span class="token operator">=</span> factory<span class="token punctuation">.</span><span class="token function">newDocumentBuilder</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// 4.通过 DocumentBuilder 对象去解析获取 Document 对象</span>
<span class="token class-name">Document</span> doc <span class="token operator">=</span> builder<span class="token punctuation">.</span><span class="token function">parse</span><span class="token punctuation">(</span>file<span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br></div></div><p>步骤流程图以及获取 Document 对象方法选用</p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/document1.png" alt=""><br></p> <h5 id="_5-4-3-3-解析案例"><a href="#_5-4-3-3-解析案例" class="header-anchor">#</a> 5.4.3.3 解析案例</h5> <p><strong>需求</strong> : 获取第二个联系人的名字</p> <p><strong>步骤</strong>:
1.获取 Document 对象.
2.获取根节点/根标签.
3.获取第二个 linkman 节点.
4.获取名字节点.
5.获取名字节点的文本内容.</p> <p><strong>常用API</strong></p> <blockquote><p><strong>Document 对象</strong>
Element getDocumentElement(): 获取根节点.</p> <p><strong>Element 对象</strong>
​	NodeList getElementsByTagName(String name):通过标签名获取标签列表.</p> <p><strong>Node 对象</strong>
​	String getTextContent():获取节点的文本内容
​	void setTextContent(String content);设置节点的文本内容</p></blockquote> <p><strong>代码实现</strong></p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/DOM-opra1.png" alt=""><br></p> <h5 id="_5-4-3-4-拓展案例"><a href="#_5-4-3-4-拓展案例" class="header-anchor">#</a> 5.4.3.4 拓展案例</h5> <p><strong>需求</strong> : 增加一个新的联系人信息</p> <p><strong>步骤</strong>:</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token comment">// 1 获取文档对象</span>
<span class="token comment">// 2 获取根元素</span>
<span class="token comment">// 3 创建一个linkman代码片段</span>
	<span class="token comment">// 3.1 创建 name,email,address,group 子元素</span>
	<span class="token comment">// 3.2 给 name,email,address,group 添加文本内容</span>
	<span class="token comment">// 3.3 将 name,email,address,group元素作为 linkman 的子元素</span>
	<span class="token comment">// 3.4 将 linkman 作为根元素的子元素</span>
<span class="token comment">// 4 同步操作</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br></div></div><p><strong>常用API</strong></p> <blockquote><p><strong>Document 对象</strong>:
Element getDocumentElement(): 获取根节点.</p> <p><strong>Element 对象</strong>:
​	NodeList getElementsByTagName(String name):通过标签名获取标签列表.</p> <p><strong>Node 对象</strong>:
​	String getTextContent():获取节点的文本内容
​	void setTextContent(String content);设置节点的文本内容</p></blockquote> <p><strong>代码实现</strong></p> <p><img src="https://cdn.jsdelivr.net/gh/langfeiyes/images-khub/xmlinsert.png" alt=""><br></p> <h5 id="_5-4-3-5-xml-约束-了解"><a href="#_5-4-3-5-xml-约束-了解" class="header-anchor">#</a> 5.4.3.5 XML 约束（了解）</h5> <p>XML 文件,主要的作用是用来传输数据,以及作为配置文件.
如下面的代码,使用XML文件,将数据由 A 传输到 B,那么 B 就可以创建一个 User对象来保存 XML 中的数据.</p> <div class="language-xml line-numbers-mode"><pre class="language-xml"><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>users</span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>user</span><span class="token punctuation">&gt;</span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>username</span><span class="token punctuation">&gt;</span></span>xiaoming<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>username</span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>user</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>users</span><span class="token punctuation">&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><p>但是,B 在读取数据的时候,写死只能读取 user 标签,把该标签中的内容放在对应的 User 对象中,如果 XML 中的标签不再是 user,而是 user1,如下图:</p> <div class="language-xml line-numbers-mode"><pre class="language-xml"><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>users</span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>user1</span><span class="token punctuation">&gt;</span></span>
		<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>username</span><span class="token punctuation">&gt;</span></span>xiaoming<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>username</span><span class="token punctuation">&gt;</span></span>
	<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>user1</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>users</span><span class="token punctuation">&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><p>上面的 XML 文件,语法没有问题,从A 传递给B 之后，B 不能将数据封装到 User 对象中.</p> <p>可以使用XML约束来规范 XML 内容的写法.(dtd,schema)
XML约束,了解即可,因为以后我们更多的是使用到别人提供好的约束文件,使用 idea 等工具,利用代码提示的方式写好 XML 即可.</p> <h2 id="六、小结与作业"><a href="#六、小结与作业" class="header-anchor">#</a> 六、小结与作业</h2> <h3 id="_6-1-小结"><a href="#_6-1-小结" class="header-anchor">#</a> 6.1 小结</h3> <ul><li><p>掌握idea开发工具环境的搭建</p></li> <li><p>掌握代码编码规范与命名规范</p></li> <li><p>掌握单元测试 JUnit 的使用+创建测试目录+生成测试类+测试对应的方法</p></li> <li><p>掌握配置文件-Properties + xml</p></li> <li><p>了解 xml 的语法结构，能够看得懂xml语法，能够书写和修改xml内容即可</p></li> <li><p>了解 DOM Document Object Model</p></li> <li><p>掌握使用 DOM 操作去读取 xml 中第二个联系人的信息</p></li></ul> <h3 id="_6-2-作业"><a href="#_6-2-作业" class="header-anchor">#</a> 6.2 作业</h3> <ul><li><p>使用 JUnit 来完成某个类功能的测试(熟练使用)</p></li> <li><p>掌握 properties 文件的书写和解析(写代码练习)</p></li> <li><p>掌握 xml 的书写</p></li> <li><p>DOM 解析得到第二个联系人信息</p></li></ul></div></div>  <div class="page-edit"><!----> <div class="tags"><a href="/tags/?tag=JUnit" title="标签">#JUnit</a></div> <!----></div> <div class="page-nav-wapper"><div class="page-nav-centre-wrap"><a href="/pages/16b819/" class="page-nav-centre page-nav-centre-prev"><div class="tooltip">IO</div></a> <a href="/pages/1fdc1c/" class="page-nav-centre page-nav-centre-next"><div class="tooltip">反射与内省机制</div></a></div> <div class="page-nav"><p class="inner"><span class="prev">
        ←
        <a href="/pages/16b819/" class="prev">IO</a></span> <span class="next"><a href="/pages/1fdc1c/">反射与内省机制</a>→
      </span></p></div></div></div> <div class="article-list"><div class="article-title"><a href="/archives/" class="iconfont icon-bi">最近更新</a></div> <div class="article-wrapper"><dl><dd>01</dd> <dt><a href="/pages/0c07b2/"><div>
            IT杂货铺
            <!----></div></a> <span class="date">03-23</span></dt></dl><dl><dd>02</dd> <dt><a href="/pages/705b35/"><div>
            人事百问
            <!----></div></a> <span class="date">03-22</span></dt></dl><dl><dd>03</dd> <dt><a href="/pages/78eb56/"><div>
            MyBatis-Plus
            <!----></div></a> <span class="date">03-12</span></dt></dl> <dl><dd></dd> <dt><a href="/archives/" class="more">更多文章&gt;</a></dt></dl></div></div></main></div> <div class="footer"><div class="icons"><a href="mailto:langfeiyes@163.com" title="发邮件" target="_blank" class="iconfont icon-youjian"></a><a href="https://github.com/langfeiyes" title="GitHub" target="_blank" class="iconfont icon-github"></a><a href="https://music.163.com/#/playlist?id=755597173" title="听音乐" target="_blank" class="iconfont icon-erji"></a></div> 
  Theme by
  <a href="https://github.com/xugaoyi/vuepress-theme-vdoing" target="_blank" title="本站主题">Vdoing</a> 
    | Copyright © 2024-2024
    <span><a href="https://beian.miit.gov.cn/" target="_blank">粤ICP备18007927号-1</a></span></div> <div class="buttons"><div title="返回顶部" class="button blur go-to-top iconfont icon-fanhuidingbu" style="display:none;"></div> <div title="去评论" class="button blur go-to-comment iconfont icon-pinglun" style="display:none;"></div> <div title="主题模式" class="button blur theme-mode-but iconfont icon-zhuti"><ul class="select-box" style="display:none;"><li class="iconfont icon-zidong">
          跟随系统
        </li><li class="iconfont icon-rijianmoshi">
          浅色模式
        </li><li class="iconfont icon-yejianmoshi">
          深色模式
        </li><li class="iconfont icon-yuedu">
          阅读模式
        </li></ul></div></div> <!----> <!----> <!----></div><div class="global-ui"><div></div></div></div>
    <script src="/assets/js/app.a2a00aa5.js" defer></script><script src="/assets/js/2.256f807a.js" defer></script><script src="/assets/js/28.b383a871.js" defer></script>
  </body>
</html>
